package com.community.controller;

import com.community.base.BaseController;
import com.community.common.Const;
import com.community.common.ServerResponse;
import com.community.util.LoginUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/commentOperationController/")
@CrossOrigin(origins = Const.REQUESTURL,maxAge = 3600,allowCredentials = "true")
public class IntergralController extends BaseController {



    /**
     * 查询用户交易记录
     * @param pageNum 页码
     * @param order 排序
     * @param userName 用户名
     * @return
     */
    @GetMapping("selectRecord.do")
    public ServerResponse<PageInfo> selectIntegralByUserName(@RequestParam(value = "pageNum") int pageNum,
                                                             @RequestParam(value = "order",
                                                                     defaultValue = "ir.create_time desc") String order,
                                                             @RequestParam(value = "userName") String userName, HttpServletRequest request){

        if(!LoginUtil.isLogin(request,userName)){
            return ServerResponse.createByErrorMessage(Const.Msg.PARAMTERERROR);
        }
        return iIntegralService.selectIntegralByUserName(pageNum,order,userName);
    }


    /**
     * 查询用户剩余积分及
     * @param userName
     * @return
     */
    @GetMapping("selectSurplus.do")
    public ServerResponse<Integer> selectSurplusByUserName(@RequestParam(value = "userName") String userName,HttpServletRequest request){
        return iIntegralService.selectSurplusByUserName(userName,request);
    }

}
